mui.init({
	//下拉刷新
	pullRefresh: {
		container: "#refreshContainer", //待刷新区域标识，querySelector能定位的css选择器均可，比如：id、.class等
		up: {
			height: 50, // 可选.默认50.触发上拉加载拖动距离
			auto: true, // 可选,默认false.自动上拉加载一次
			contentrefresh: "正在加载...", // 可选，正在加载状态时，上拉加载控件上显示的标题内容
			contentnomore: '没有更多的数据了', // 可选，请求完毕若没有更多数据时显示的提醒内容；
			callback: pullupRefresh //加载数据方法 
		}
	}
});

/*搜索*/
$('#search_text').on('keyup', function(event) {
	if(event.keyCode == "13") {
		var search_text = $('#search_text').val();
		pagenum = 0;
		mui.init();
		document.activeElement.blur(); //关闭键盘
		$("#number").val(1);
		$('#landing_list').html('');
		landing_page_user(search_text);
	}
});

//下拉加载
function pullupRefresh() {
	setTimeout(function() {
		mui('#refreshContainer').pullRefresh().disablePullupToRefresh();
		setTimeout(function() {
			var isOver = $("#isOver").val(); //加载判断
			var search_text = $('#search_text').val(); //搜索内容
			mui('#refreshContainer').pullRefresh().endPullupToRefresh((isOver)); //参数为true代表没有更多数据了。  
			landing_page_user(search_text); //搜索动态
		}, 500);
	}, 500);
}

/**
 * 搜索-用户列表接口
 */
//请求方法
function landing_page_user(search_text) {
	var number = $("#number").val();
	interfRequest.searchUser.data = {
		content: search_text,
		number: number,
		pagesize: 5
	}
	socialRequest(interfRequest.searchUser)
}

//成功函数回调
function searchUserHandle(data) { 
	var number = $("#number").val(); 
	if(number == 1) {
		if(data.data.length == 0) {
			$("#landing_list").html('<div class="landign_no_data2"><img style="width:30%" src="../../images/wdl.png"><p style="font-size:18px;">未查询到数据</p></div>');
			mui('#refreshContainer').pullRefresh().endPullupToRefresh(true);
		} else {
			user_data(data);
		}
	} else {
		if(data.data.length == 0) {
			$("#isOver").val(true);
			mui('#refreshContainer').pullRefresh().endPullupToRefresh(true);
		} else {
			user_data(data);
		}
	}

}
//用户数据处理
function user_data(data) {
	var isOver = $("#isOver").val();
	if(isOver == "false") {
		var number = $("#number").val();
		var ye = Number(number) + Number(1);
		$("#number").val(ye++);  
		mui('#refreshContainer').pullRefresh().endPullupToRefresh(true); //停止正在加载
		mui('#refreshContainer').pullRefresh().enablePullupToRefresh(); //显示上拉加载文字
	} else {
		$("#isOver").val(true);
		mui('#refreshContainer').pullRefresh().endPullupToRefresh(true);
	}
	var html = '';
	for(var i = 0; i < data.data.length; i++) {
		var is_valid = data.data[i].is_valid; //是否关注
		var user_id = localStorage.getItem("user_id"); //user_id
		var head_img_url = data.data[i].head_img_url
		html += '<li class="mui-table-view-cell landing_user_righr_posi">';
		html += '<div class="landing_user_img">';
		if(!head_img_url){
			html += '<img src="../../images/log.png" alt="" />';	
		}else{
			html += '<img src="https://ypao.oss-cn-shenzhen.aliyuncs.com/' + data.data[i].head_img_url + '" alt="" />';
		} 
		html += '</div>';
		html += '<span class="landing_user_fans">' + data.data[i].nickname + '</span>';
		html += '<p class="landing_user_text">粉丝：' + data.data[i].fans + '</p>';
		if(user_id != data.data[i].id) {
			if(is_valid == 1) {
				html += '<span class="landing_user_right" id="' + data.data[i].id + '" >已关注</span>';
			} else {
				html += '<span class="landing_user_right" id="' + data.data[i].id + '" >+关注</span>';
			}
		}

		html += '</li>';
	}
	$('#landing_list').append(html);
}

//关注用户  
mui('body').on('tap', '.landing_user_right', function() {
	var mag = $("#mag").val(); //提示  
	if(mag == "请先登录") { //判断是否登录  
		var btnArray = ['否', '是'];
		mui.confirm(mag, '提示', btnArray, function(e) {
			if(e.index == 1) {
				/*mui.openWindow({
					url: '../user/login.html',
					id: 'login',
				});*/
				window.top.location.href = '../user/login.html';
			} else {}
		})
	} else {
		var publisher = $(this).attr("id"); //用户id  
		var user_id = localStorage.getItem("user_id"); //user_id
		$(this).addClass("follow").parent().siblings().children(".landing_user_right").removeClass("follow"); 
		interfRequest.concern.data = {
			user_id: user_id,
			passive_user_id: publisher //true	普通参数	int		我关注的人id
		}
		socialRequest(interfRequest.concern); //异常处理   
	}
});

//取消
mui('body').on('tap', '.search_right', function() {
	window.top.location.href = '../../Recommend.html';
});

//返回到首页
mui.back = function() {
	window.top.location.href = '../../Recommend.html';
}

//查看搜索全部
mui('body').on('tap', '.all_btn', function() {
	var search_text = $('#search_text').val();  
	mui.openWindow({
		url: 'landing_page1.html',
		id: 'landing_page1',
		extras: {
			search: search_text,
		},
		createNew: true
	});
	//window.top.location.href = 'landing_page2.html';

});

//查看搜索动态
mui('body').on('tap', '.dynamic_btn', function() {
	var search_text = $('#search_text').val(); 
	mui.openWindow({
		url: 'landing_page3.html',
		id: 'landing_page3',
		extras: {
			search: search_text,
		},
		createNew: true
	});
	//window.top.location.href = 'landing_page2.html';

});

//用户信息
function user_info() {
	interfRequest.user_info.data = {
		refresh: 1 //true	普通参数	string		刷新状态1代表刷新
	}
	socialRequest(interfRequest.user_info); //异常处理 
}

//页面进入执行方法
window.onload = function() {
	mui.plusReady(function() {
		var self = plus.webview.currentWebview(); 
		$('#search_text').val(self.search);
		user_info(); //用户信息 
	});
}